package com.lwj.liwanjia.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;


import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;

import org.litepal.LitePalApplication;

import java.util.ArrayList;
import java.util.List;

import cn.jpush.android.api.JPushInterface;
import constants.Constants;

/**
 * Created by Administrator on 2017/6/9.
 */

public class MyApplication extends Application {
    private List<Activity> activities;
    private static MyApplication myApplication;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        myApplication = this;
        JPushInterface.init(this);
        LitePalApplication.initialize(this);
        UMShareAPI.get(this);
        PlatformConfig.setWeixin("wx913adde2e48183ef", "b56891e09b99584b6b50946eeea1cca5");
        PlatformConfig.setQQZone("1106550078", "pYsl4rPGiiMiOV7b");
    }

    public static MyApplication getInstance() {
        return myApplication;
    }

    public void addActivity(Activity activity) {
        if (activities == null) {
            activities = new ArrayList<>();
        }
        activities.add(activity);
    }

    public void removeActivity(Activity activity) {
        if (activities != null) {
            activities.remove(activity);
        }
    }

    public void clearActivity() {
        if (activities != null) {
            synchronized (activities) {
                for (Activity act : activities) {
                    act.finish();
                }
            }
        }
    }

    public void exitApp() {
        if (activities != null) {
            synchronized (activities) {
                for (Activity act : activities) {
                    act.finish();
                }
            }
        }
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(0);
    }
}
